﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Practices.Prism.Regions;
using TimeSplicerModule.DomainModels;
using TimeSplicerModule.ViewModels;
using TimeSplicerModule.Factories;
using Microsoft.Practices.ServiceLocation;
using Microsoft.Practices.Unity;
using TimeSplicerModule.Controllers;

namespace TimeSplicerModule.Views
{
    /// <summary>
    /// Interaction logic for JobRoleListView.xaml
    /// </summary>
    public partial class JobRoleListView : UserControl, INavigationAware
    {
        private JobRoleListViewModel Model;
        private readonly IUnityContainer _container;
        private readonly IJobRoleFactory _jobRoleFactory;
        private readonly IJobRoleController _jobRoleController;

        public JobRoleListView(IUnityContainer container, IJobRoleFactory jobRoleFactory, IJobRoleController jobRoleController)
        {
            InitializeComponent();

            _container = container;
            _jobRoleFactory = jobRoleFactory;
            _jobRoleController = jobRoleController;
        }

        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            return false;  //throw new NotImplementedException();
        }

        public void OnNavigatedFrom(NavigationContext navigationContext)
        {
            //throw new NotImplementedException();
        }

        public void OnNavigatedTo(NavigationContext navigationContext)
        {
            Model = new JobRoleListViewModel();
            Model.JobRoles = _jobRoleFactory.GetList();

            this.DataContext = Model;
        }

        private void newButton_Click(object sender, RoutedEventArgs e)
        {
            _jobRoleController.NavigateToItemView();
        }

        private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            DataGrid grid = sender as DataGrid;

            if (grid.SelectedItem != null)
            {
                var role = grid.SelectedItem as JobRoleModel;
                _jobRoleController.NavigateToItemView(role.JobRoleGuid);
            }
        }


    }
}
